//
//  LotteryViewModel.m
//  MoXiProject
//
//  Created by 周筱雯 on 2017/7/18.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#import "LotteryViewModel.h"
#import "LotteryTypeModel.h"

@implementation LotteryViewModel

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.userLotteryList = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return self;
}

//获取最新一期开奖记录
-(RACSignal *) getLotteryTypeRequestParameter{
    
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        
        [RequestOperationManager findLotteryTypeParametersDic:[[NSDictionary alloc] init] success:^(NSDictionary *result) {
            
            if (result) {
                
                if ([self.userLotteryList count] == 0) {
                    
                    [self.userLotteryList removeAllObjects];
                }
                
                self.userLotteryList = (NSMutableArray *)[MTLJSONAdapter modelsOfClass:[LotteryTypeModel class] fromJSONArray:result[@"result"] error:nil];
                
            }
            
            [subscriber sendNext:result];
            [subscriber sendCompleted];
            
        } failture:^(id result) {
            
            [self.userLotteryList removeAllObjects];
            [subscriber sendError:result];
        }];
        return nil;
    }];
}


@end
